package com.zkgengkun.repository;

import com.zkgengkun.domain.Blog;
import com.zkgengkun.domain.Character;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.PagingAndSortingRepository;

/**
 * @author gengshikun
 * @date 2016/12/6
 */
@CacheConfig(cacheNames = "characters")
public interface CharacterRepository extends PagingAndSortingRepository<Character, String>, JpaRepository<Character, String> {

    /**
     * 列表页分页查询
     *
     * @param query
     * @param pageable
     * @return
     */
    Page<Character> findByNameLike(String query, Pageable pageable);

    Character findByName(String name);

    @CacheEvict(key = "'character:'+#p0.characterId")
    Character save(Character character);

    @CacheEvict(key = "'character:'+#p0.characterId")
    Character saveAndFlush(Character character);

    @Cacheable(key = "'character:'+#p0")
    Character findOne(String characterId);


}
